<template>
  <el-dialog
    title="下发账号"
    :visible.sync="dialogValue"
    width="600px"
    append-to-body
  >
    <SubmitForm
      :rule-form="ruleForm"
      :rules="rules"
      :form-list="formList"
      @close="onPageBack"
      @save="onSave"
    />
  </el-dialog>
</template>

<script>
import { http } from '@/api'
export default {
  name: 'FormAdd',
  data() {
    return {
      dialogValue: false,
      ruleForm: {
        enterpriseId: '',
        username: '',
        password: '',
        status: 0
      },
      rules: {
        enterpriseId: [{ required: true, message: '不能为空' }],
        username: [{ required: true, message: '不能为空' }],
        password: [{ required: true, message: '不能为空' }]
      },
      formList: [
        {
          key: 'enterpriseId',
          name: 'select',
          label: '企业选择',
          options: [
          ],
          colSpan: 24
        },
        {
          key: 'username',
          name: 'input',
          label: '用户账号',
          colSpan: 12
        },
        {
          key: 'password',
          name: 'input',
          label: '密码',
          colSpan: 12
        },
        {
          key: 'status',
          name: 'switch',
          label: '是否启用',
          colSpan: 24,
          defaultValue: 0,
          activeValue: 0,
          inactiveValue: 1
        }
      ]
    }
  },
  created() {

  },
  methods: {
    async open() {
      http.enterprise.page().then(res => {
        this.formList[0].options = res.data.records.map(el => {
          return {
            value: el.id,
            name: el.enterpriseName
          }
        })
      })
      this.dialogValue = true
    },
    onPageBack() {
      this.$emit('get-page')
      this.dialogValue = false
    },
    onSave() {
      http.enterpriseAccount.distribute({ ...this.ruleForm }).then(res => {
        this.$message.success(res.msg)
        this.onPageBack()
      })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
